<?php
/**
 * Joomla! 1.5 component NS Pro
 *
 * @version $Id: view.html.php 2009-04-28 01:47:12 svn $
 * @author Christopher Mavros
 * @package Joomla
 * @subpackage NS Pro
 * @license GNU/GPL
 *
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

// Import Joomla! libraries
jimport( 'joomla.application.component.view');
class NsproViewSubscribers extends JView {

    function display($tpl = null)
    {

        //global $mainframe, $option;
        $mainframe = JFactory::getApplication();
        $option = JRequest::getCmd('option');
        
        $model      =& $this->getModel();

        $limit      = $mainframe->getUserStateFromRequest( 'global.subscriber.limit', 'limit', $mainframe->getCfg('list_limit'), 'int' );
        if ( (isset($_POST["searchsubscribers"])) && (isset($_POST["new_search"]))) {
          $limitstart = 0;
        }
        else {
          $limitstart = $mainframe->getUserStateFromRequest( $option.'.subscriber.limitstart', 'limitstart', 0, 'int' );
        }

        JToolBarHelper::title(   JText::_( 'NS Pro Manager' ), 'generic.png' );
        JToolBarHelper::custom('bouncecheck', 'preview.png', 'preview.png', 'Run Bounce Check', false, false);
        JToolBarHelper::custom('massconfirm', 'apply.png', 'apply.png', 'Confirm', true, false);
        JToolBarHelper::custom('massunconfirm', 'cancel.png', 'cancel.png', 'Unconfirm', true, false);
        JToolBarHelper::custom('resendconfirm', 'forward.png', 'forward.png', 'Re-Send Confirmation', true, false);
        JToolBarHelper::divider();
        JToolBarHelper::deleteList();
        JToolBarHelper::editListX();
        JToolBarHelper::addNewX();
        JToolBarHelper::preferences('com_nspro', 400);
        JToolBarHelper::help('../../help.html', true);

        $filter_subs = 0;
        if (isset($_POST['select_list'])) {
          $filter_subs = $_POST['select_list'];
        }
        
        // Anti XSS
        $subsearchkey = '';
        if (isset($_POST["searchsubscribers"]) && (isset($_POST["subsearchkey"])) && ($_POST["subsearchkey"] !== '')) {
          $subsearchkey = htmlentities($_POST["subsearchkey"], ENT_COMPAT, "UTF-8");
        }

        jimport('joomla.html.pagination');
        if ($subsearchkey !== "") {
          $total = $model->getSubsCountSearch($subsearchkey, $filter_subs);
        }
        else {
          $total = $model->getSubsCount($filter_subs);
        }

        $pagination = new JPagination( $total, $limitstart, $limit );

        // search
        if ($subsearchkey !== "") {
          $subs = $model->getSubsSearch($subsearchkey, $limit, $limitstart, $filter_subs);
        }
        else {
          $subs = $model->getSubs($limit, $limitstart, $filter_subs);
        }
        //$allSubs = $model->getAllSubs();

        $this->assignRef('pagination',  $pagination);
        $this->assignRef('subs', $subs);
        //$this->assignRef('allSubs', $allSubs);
        $this->assignRef('filter_subs', $filter_subs);

        $state =& $this->get( 'state' );
        $olists['order_Dir'] = $state->get( 'filter_order_Dir' );
        $olists['order']     = $state->get( 'filter_order' );
        $this->assignRef( 'olists', $olists );

        parent::display($tpl);
    }
}
?>